<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/8
 * Time: 13:46
 */
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use think\Db;

class IntegralController extends AdminBaseController
{
    /*
     * 后台看流水   督导看自己管辖的店铺       总公司看所有
     * 增加打印条件
     * */

    public function added()
    {
        /**搜索条件**/
        $param = $this->request->param();
        $where = array();
        if (isset($param['start_time']) && !empty($param['start_time'])) {
            $where['ctime'][] = array('egt', strtotime($param['start_time']));
        }
        if (isset($param['end_time']) && !empty($param['end_time'])) {
            $where['ctime'][] = array('elt', strtotime($param['end_time']));
        }
        isset($param['orderNo']) ? $where['orderid'] = $param['orderNo'] : '';
        $storeid = isset($param['storeid']) ? $param['storeid'] : '';
        $uid = cmf_get_current_admin_id();
        $uinfo = get_operator_data($uid);//登陆者信息
        if(isset($storeid) && !empty($storeid)){
            $where['storeid'] = $storeid;
            $map['id']=$storeid;
        }else{
            $userList=get_user_list($uid);
            $uid_list_str=toStr($userList,'userid');
            $uid_list_str.=','.$uid;
            $store_id_list=get_store_list($uid_list_str);
            if($store_id_list){
                $where['storeid']=array('in',$store_id_list);
                $map['id']=array('in',$store_id_list);
            }
        }
        $mname = isset($param['mname']) ? $param['mname'] : '';
        if (!empty($mname)) {
            $mid_str = '';
            $con['uname'] = array('like', "%$mname%");
            $minfo = Db::name('Member')->where($con)->field('id')->select()->toarray();
            $mid_str = toStr($minfo, 'id');
            $where['userid'] = array('in', $mid_str);
        }
            $list = Db::name('IntegralRecord')->where($where)->order("id DESC")->paginate(10);
            $map['status'] = 1;
            $list_store_list = Db::name('Store')->where($map)->select()->toarray();//正在运营的店铺列表
            // 获取分页显示
            $page = $list->render();
            $this->assign("list_store_list", $list_store_list);
            $this->assign("page", $page);
            $this->assign("list", $list);
            return $this->fetch();

    }
}